<template>
  <div id="writePoint">
  <group>
      <x-textarea :max="20" placeholder="新鲜事" v-model="content" @on-focus="onEvent('focus')" @on-blur="onEvent('blur')" ref='content'></x-textarea>
  </group>
  
  <x-button :text="submit001" :disabled="disable001" @click.native="processButton001" type="primary" style="background-color:rgb(216, 65, 65) !important;"></x-button>

  <toast v-model="showPositionValue" type="text" :time="1000" is-show-mask text="请退出重新发布" :position="position"></toast>
  </div>
</template>

<script>

import { Grid, XTextarea, Group, XButton, Toast } from 'vux'
export default {
  components: {
    Grid,
    XTextarea,
    Group,
    XButton,
    Toast
  },
  data () {
    return {
      items: [],
      submit001: '发布',
      disable001: false,
      content: '',
      position: 'default',
      showPositionValue: false
    }
  },
  mounted: function () {
  },
  methods: {
    refresh: function (done) {
    },
    showPosition: function (position) {
      this.position = position
      this.showPositionValue = true
    },
    onEvent (event) {
      console.log('on', event)
    },
    processButton001 () {
      this.submit001 = 'processing'
      this.disable001 = true
      var txt = this.content
      let config = {
        headers: {'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/json', 'Accept': 'application/json'},
        data: {
          pointText: txt,
          createBy: '1'
        },
        responseType: 'json',
        method: 'post'
      }
      var that = this
      this.$ajax('/api/cms/home/viewpoints/add', config).then(function (response) {
        if (response.data.code === '00') {
          that.$router.push('/home/Index')
          that.submit001 = '发布'
          that.disable001 = false
          that.$destroy(true)
        } else {
          that.showPosition('top')
          that.submit001 = '发布'
          that.disable001 = false
        }
      }).catch(function (error) {
        console.log(error)
      })
    }
  }
}
</script>

<style scoped>

</style>
